﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 创建者：王明亮
 * 创建时间：2022/8/19 23:37:40
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;


namespace Aliang.Common.Helper.Log
{
    /// <summary>
    /// LogHelper 的摘要说明
    /// </summary>
    public class LogHelper
    {
        /// <summary>
        /// 记录指定的日志
        /// </summary>
        /// <param name="logName">日志名</param>
        /// <param name="category">日志类别</param>
        /// <param name="log">要写日志的流</param>
        /// <param name="lineId">线路id</param>
        /// <param name="rq"></param>
        public static void Log(string lineId, object logName, string category, string log, DateTime rq)
        {
            try
            {
                var path = "Log\\" + rq.ToString("yyyyMMdd") + "\\" + lineId;
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                string fileName = path + "\\" + logName + ".txt";
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("HH:mm:ss"), category, log,
                                                 Environment.NewLine));
            }
            catch (Exception ex)
            {

            }
        }
        public static void Log(string log)
        {
            try
            {
                const string path = "Log\\";
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                var fileName = path + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                File.AppendAllText(fileName,
                                   string.Format("[{0}]{1}{2}", DateTime.Now.ToString("HH:mm:ss"), log,
                                                 Environment.NewLine));
            }
            catch (Exception ex)
            {

            }
        }
        public static void Log(string category, string log)
        {
            try
            {
                const string path = "Log";
                if (!Directory.Exists(path))
                    Directory.CreateDirectory(path);

                string fileName = path + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("HH:mm:ss"), category, log,
                                                 Environment.NewLine));
            }
            catch (Exception ex)
            {

            }
        }
    }
}
